package com.team.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.team.dao.DeptMapper;
import com.team.dao.SectionMapper;
import com.team.entity.Dept;
import com.team.entity.Section;
import com.team.service.SectionService;
import com.team.vo.Cascader;
import com.team.vo.DeptUtilVo;
import com.team.vo.Result;
import com.team.vo.SectionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : 陈灰灰
 * @Date: 2022/10/13/20:20
 * @Description:
 */
@Service
public class SectionServiceImpl implements SectionService {
    @Autowired
    private SectionMapper sectionMapper;
    private DeptMapper deptMapper;


    /**
     * 选择所有部分
     * @param sectionVo 部分签证官
     * @return {@link Result}
     */
    @Override
    public Result selectAllSections(SectionVo sectionVo) {
        List<Section> sectionsList = sectionMapper.queryAllSelect(sectionVo.getName(),sectionVo.getStatus());
        return new Result(200,"查询科室成功",sectionsList);
    }

    @Override
    public Result selectAllSections(int id) {
        return null;
    }

    @Override
    public Result selectAll() {
        List<Dept> depts = sectionMapper.selectAllid();
        List<DeptUtilVo> frist=new ArrayList<>();
        for (Dept dept:depts){
            DeptUtilVo deptUtilVo = new DeptUtilVo();
            List<Section> sections = sectionMapper.selectAllByDeptId(dept.getId());
            deptUtilVo.setDept(dept);
            deptUtilVo.setSections(sections);
            frist.add(deptUtilVo);
        }
        return new Result(200,"查看成功",frist);
    }
    @Override
    public Result updateSection(Section section) {
        sectionMapper.updateByPrimaryKey(section);
        return new Result(200,"修改科室成功");
    }

    @Override
    public Result addSection(Section section) {
        sectionMapper.insertSelective(section);
        return new Result(200,"添加成功");
    }

    @Override
    public Result selectAllSectionByDeptId(int currentPage, int pageSize, Integer id) {
        PageHelper.startPage(currentPage,pageSize);
        List<Section> sections = sectionMapper.selectAllByDeptSections(id);
        PageInfo<Section> sectionPageInfo = new PageInfo<>(sections);
        return new Result(200,"查询成功",sectionPageInfo);
    }

    @Override
    public Result updateByPrimaryKeySelective(Section record) {
        int i = sectionMapper.updateByPrimaryKeySelective(record);
        return new Result(200,"修改成功");
    }

    @Override
    public Result selectAllByIds(int id) {
//        List<Section> sections = sectionMapper.selectAllByIds(id);
        Section section = sectionMapper.selectByPrimaryKey(id);
//        return new Result(200,"查询成功",sections);
        return new Result(200,"查询成功",section);

    }
}
